package com.javashow.dao.impl;

import java.util.Iterator;
import java.util.List;

import javax.annotation.Resource;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.stereotype.Repository;

import com.javashow.dao.ITestDao;
import com.javashow.pojo.Log;
import com.javashow.pojo.Person;

@Repository("testDao")
public class TestDaoImpl implements ITestDao {
	
	@Resource
	private SessionFactory sessionFactory;
	
	public void test() {
		System.out.println("dao excute!!!");
		
		Session session = sessionFactory.getCurrentSession();
		
		Query query = session.createQuery("from Person");
		
		List<Person> list = query.list();
		
		Iterator it = list.iterator();
		
		while(it.hasNext()) {
			Person person = (Person) it.next();
			
			System.out.println(person.getName() + "   " + person.getBirthday());
		}
		
	}

	@Override
	public void insertPerson(Person person) {

		sessionFactory.getCurrentSession().save(person);
	}

	@Override
	public void insertLog(Log log) {

        sessionFactory.getCurrentSession().save(log);
	}
}













